package com.example.Servlet;

import com.example.dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class ResetPwd extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*  重置密码  */
        resp.setContentType("text/html;charset=utf-8");
        String tel = req.getParameter("tellphone");
        String newpsd = req.getParameter("newpwd");
        PrintWriter out = resp.getWriter();
        if (new UserDaoImpl().updatePwd(tel,newpsd) > 0){
            System.out.println("密码修改成功");
            out.print("修改成功");
            resp.sendRedirect("/Barbr/html/login.jsp");
        }else{
            out.print("修改失败");
            System.out.println("密码修改失败!");
        }
    }
}
